package com.yoomiito.app.utils.video

import android.media.MediaPlayer
import cn.droidlover.xdroidmvp.cache.SharedPref
import com.yoomiito.app.Constant
import com.yoomiito.app.base.App
import com.yoomiito.app.model.colleage.SubjectPlayInfo

class VideoUtils {

    companion object {
        fun savePlayRecord(id: Long, position: Int) {
            val progress = SharedPref.getInstance(App.getInstance()).getListData(Constant.SubjectProgress, SubjectPlayInfo::class.java)
            for (it in progress) {
                if (it.productId == id) {
                    it.playPosition = position
                    SharedPref.getInstance(App.getInstance()).remove(Constant.SubjectProgress)
                    SharedPref.getInstance(App.getInstance()).putListData(Constant.SubjectProgress, progress)
                    return
                }
            }
            val playInfo = SubjectPlayInfo()
            playInfo.productId = id
            playInfo.playPosition = position
            progress.add(playInfo)
            SharedPref.getInstance(App.getInstance()).remove(Constant.SubjectProgress)
            SharedPref.getInstance(App.getInstance()).putListData(Constant.SubjectProgress, progress)
            return
        }

        fun getPlayRecord():List<SubjectPlayInfo>{
            return SharedPref.getInstance(App.getInstance()).getListData(Constant.SubjectProgress, SubjectPlayInfo::class.java)
        }

        fun removePlayRecord(){
            SharedPref.getInstance(App.getInstance()).remove(Constant.SubjectProgress)
        }
    }
}